package edu.uclm.esi.tysw.tusEntradas.persistence;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;

import edu.uclm.esi.tysw.tusEntradas.domain.Espectaculo;

public class EspectaculoDAO {

	public static void insert(Espectaculo canal) throws SQLException {
		Conexion bd = Broker.get().getBD();
		try {
			CallableStatement cs=bd.prepareCall("{call insertarCanal (?, ?)}");
			//cs.setString(1, canal.getUser().getEmail());
			//cs.setString(2, canal.getName());
			cs.executeUpdate();
		}
		finally {
			bd.close();
		}
	}
	
	public static ArrayList<ArrayList<String>> getAllEspectaculo() throws SQLException {
		Conexion bd = Broker.get().getBD();
		try {
			CallableStatement cs=bd.prepareCall("{call obtenerSesionesTodosEspectaculos ()}");
			
			
			ResultSet resultset=cs.executeQuery();

			ArrayList<ArrayList<String>> results = new ArrayList<ArrayList<String>>();
			ResultSetMetaData metadata = resultset.getMetaData();
			int numcols = metadata.getColumnCount();

			while (resultset.next()) {
			    ArrayList<String> row = new ArrayList<>(numcols); // new list per row
			    int i = 1;
			    while (i <= numcols) {  // don't skip the last column, use <=
			        row.add(resultset.getString(i++));
			    }
			    results.add(row); // add it to the result
			}
			return results;
		}
		finally {
			bd.close();
		}
	}

}
